<template>
	<!-- 采购入库 -->
	<lay-container style="padding: 0 10 0 10;">
		<lay-tab v-model="TAB_ID">
			<lay-tab-item title="单据编辑" id="1" icon="layui-icon-survey">
				<div>
					<lay-form :model="Form_Model" ref="Form_Ref" :pane="true" size="xs" labelWidth="80">
						<lay-row space="0">
							<lay-col :md="24">
								<lay-form-item>
									<lay-button size="sm" type="primary" @click="click_FORM"
										:disabled="Form_Model.table_header.state != 'A' || button_v.verify.disabled == true">验证</lay-button>
									<lay-button size="sm" type="primary" @click="click_FORM"
										:disabled="Form_Model.table_header.state != 'A' || button_v.save.disabled == true">保存</lay-button>
									<lay-button size="sm" type="danger" @click="click_FORM"
										:disabled="Form_Model.table_header.state != 'A' || button_v.finish.disabled == true">审核</lay-button>
									<lay-button size="sm" type="primary" @click="OrderBuyer_new">新建</lay-button>
									<lay-button size="sm" type="primary" @click="reloadx">清除缓存</lay-button>
								</lay-form-item>
							</lay-col>
							<lay-col md="24">
								<lay-form-item label="供应厂商" mode="inline">
									<lay-input name="sup_dbid" v-model="Form_Model.table_header.sup_dbid"
										:disabled="Form_Model.table_header.state != 'A'">
										<template #suffix>
											<lay-icon type="layui-icon-more"
												@click="handleEnterKey('in_code', Form_Model.table_header.original_no)"></lay-icon>
										</template>
									</lay-input>
								</lay-form-item>
								<lay-form-item label="单据类型" mode="inline">
									<lay-select name="type" v-model="Form_Model.table_header.type"
										:disabled="Form_Model.table_header.state != 'A' || PS == 'id'">
										<lay-select-option value="A1" label="采购入库"></lay-select-option>
										<lay-select-option value="B1" label="采购退货"></lay-select-option>
										<lay-select-option value="C1" label="赠品入库"></lay-select-option>
										<lay-select-option value="D1" label="报损出库"></lay-select-option>
									</lay-select>
								</lay-form-item>
								<lay-form-item label="单据状态" mode="inline">
									<lay-radio-group name="state" v-model="Form_Model.table_header.state">
										<lay-radio value="A" label="草稿"
											:disabled="Form_Model.table_header.state != 'A'"></lay-radio>
										<lay-radio value="B" label="审核"
											:disabled="Form_Model.table_header.state != 'B'"></lay-radio>
										<lay-radio value="C" label="作废"
											:disabled="Form_Model.table_header.state != 'C'"></lay-radio>
									</lay-radio-group>
								</lay-form-item>
								<lay-form-item label="系统单号" mode="inline">
									<lay-input name="dbid" v-model="Form_Model.table_header.dbid">
										<template #suffix>
											<lay-icon type="layui-icon-search"
												@click="EnterKey_GO_ID(Form_Model.table_header.dbid)"></lay-icon>
										</template>
									</lay-input>
								</lay-form-item>

								<lay-form-item label="创建时间" mode="inline">
									<lay-input name="time_new" v-model="Form_Model.table_header.time_new.mp"
										:disabled="Form_Model.table_header.state != 'A'">
									</lay-input>
								</lay-form-item>

								<lay-form-item label="原始单号" mode="inline">
									<lay-input name="original_no" v-model="Form_Model.table_header.original_no"
										:disabled="Form_Model.table_header.state != 'A'">
									</lay-input>
								</lay-form-item>


								<lay-form-item label="单据备注" mode="inline">
									<lay-input name="remark" v-model="Form_Model.table_header.remark"
										:disabled="Form_Model.table_header.state != 'A'"></lay-input>
								</lay-form-item>
								<lay-form-item label="修改时间" mode="inline">
									<lay-input name="time_up" v-model="Form_Model.table_header.time_up.mp"
										:disabled="Form_Model.table_header.state != 'A'">
									</lay-input>
								</lay-form-item>
							</lay-col>
						</lay-row>
						<lay-line>{{ PS }}</lay-line>
						<lay-row>
							<lay-col :md="24">
								<!-- <lay-card> -->
								<lay-table :columns="PN.columns" :dataSource="Form_Model.table_detail" size="sm"
									@row="table_click">
									<template #in_code="{ data }">
										<lay-input v-model="data.in_code" @keyup.enter="handleEnterKey('in_code', data)"
											v-if="Form_Model.table_header.state == 'A'">
											<template #suffix>
												<lay-icon type="layui-icon-more"
													@click="handleEnterKey('in_code', data)"></lay-icon>
											</template>
										</lay-input>
										<span v-else>{{ data.in_code }}</span>
									</template>
									<template #barcode="{ data }">
										<lay-input v-model="data.barcode" @keyup.enter="handleEnterKey('barcode', data)"
											v-if="Form_Model.table_header.state == 'A'" />
										<span v-else>{{ data.barcode }}</span>
									</template>
									<template #goods_name="{ data }">
										{{ data.goods_name }}
									</template>
									<template #unit="{ data }">
										{{ data.unit }}
									</template>

									<template #unit_pack="{ data }">
										{{ data.unit_pack.mp }}
									</template>
									<template #number="{ data }">
										<lay-input v-model.number="data.number" type="number"
											v-if="Form_Model.table_header.state == 'A'" />
										<span v-else>{{ data.number }}</span>
									</template>
									<template #number_unit="{ data }">
										{{ data.number_unit }}
									</template>
									<template #prc_in_actual="{ data }">
										<lay-input v-model.number="data.prc_in_actual" type="number"
											v-if="Form_Model.table_header.state == 'A'" />
										<span v-else>{{ data.prc_in_actual }}</span>
									</template>
									<template #prc_in="{ data }">
										{{ data.prc_in }}
									</template>
									<template #remark="{ data }">
										<lay-input v-model="data.remark" v-if="Form_Model.table_header.state == 'A'" />
										<span v-else>{{ data.remark }}</span>
									</template>
									<template #goods_dbid="{ data }">
										{{ data.goods_dbid }}
									</template>
									<template #id="{ data }">
										{{ data.id }}
									</template>
									<!-- <template v-slot:type="{ data }">{{ PN.type(data.type) }}</template> -->
									<!-- <template v-slot:state="{ data }"><span v-html="PN.state(data.state)"></span></template> -->
									<template v-slot:operator="{ data }" v-if="Form_Model.table_header.state == 'A'">
										<lay-button border="green" border-style="dashed" size="xs"
											@click="Del(data)">删除</lay-button>
									</template>
									<template v-slot:footer v-if="Form_Model.table_header.state == 'A'">
										<lay-row space="0">
											<lay-col :md="3"><lay-checkbox size="sm" name="RSD_ins" value="1"
													v-model="RSD_hint">重复提示</lay-checkbox></lay-col>
											<lay-col :md="20"> <lay-button border="green" border-style="dashed" size="sm"
													:fluid="true" @click="Add">新增</lay-button>
											</lay-col>
										</lay-row>

									</template>
								</lay-table>
								<!-- </lay-card> -->

							</lay-col>
						</lay-row>
					</lay-form>
				</div>
			</lay-tab-item>
			<lay-tab-item title="历史单据" id="2" icon="layui-icon-tabs">
				<lay-row space="0">
					<lay-col :md="24">
						<lay-form-item>
							<lay-button size="sm" type="primary" @click="click_OrderBuyerList">查询</lay-button>
						</lay-form-item>
					</lay-col>
				</lay-row>
				<div>
					<!-- 历史单据列表 -->
					<lay-table height="267px" :columns="PN.Table_list_header_columns" :dataSource="Table_list.list"
						size="sm" @row="Table_list_click">
						<template v-slot:operator="{ data }">
							<span v-if="data.state.val != 'A'">
								<lay-button border="green" border-style="dashed" size="xs"
									@click="Edit($event, data)">查看</lay-button></span>
							<span v-else>
								<lay-button border="green" border-style="dashed" size="xs"
									@click="Edit($event, data)">编辑</lay-button>
							</span>
						</template>
						<template #state="{ data }">
							<span v-if="data.state.val == 'A'"><lay-tag type="danger" size="sm">{{
								data.state.mp }}</lay-tag></span>
							<span v-else-if="data.state.val == 'C'"><lay-tag size="sm">{{ data.state.mp }}</lay-tag></span>
							<span v-else>{{ data.state.mp }}</span>
						</template>
						<template #type="{ data }">
							{{ data.type.mp }}
						</template>
						<template #sup_dbid="{ data }">
							{{ data.sup_dbid }}
						</template>

						<template #time_new="{ data }">
							{{ data.time_new.mp }}
						</template>
						<template #time_up="{ data }">
							{{ data.time_up.mp }}
						</template>
						<template #dbid="{ data }">
							{{ data.dbid }}
						</template>
						<template #detail_length_insert="{ data }">
							{{ data.detail_length_insert }}
						</template>
						<template #remark="{ data }">
							{{ data.remark }}
						</template>
						<template v-slot:footer>
							<lay-page v-model="page.current" :layout="layout1a" :limit=page.limit :total=page.total
								:limits="[5, 10, 30, 50, 100]" @change="change"></lay-page>
						</template>
					</lay-table>
				</div>
				<lay-line></lay-line>
				<div>
					<!-- 一张单的明细 -->
					<lay-table height="300px" :columns="PN.Table_list_detail_columns" :dataSource="Table_list.detail"
						size="sm">
						<template #goods_name="{ data }">
							{{ data.goods_name }}
						</template>


						<template #order_dbid="{ data }">
							{{ data.order_dbid }}
						</template>


						<template #goods_dbid="{ data }">
							{{ data.goods_dbid }}
						</template>

					</lay-table>
				</div>
			</lay-tab-item>
		</lay-tab>
	</lay-container>
	<!-- 商品选择弹窗 -->
	<Wingoodsx ref="goodsxRef" @topClick="goodsx_fn" />
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import MyModal from './MyModal.vue'
import { layer } from "@layui/layer-vue";
import { LayoutKey } from "@layui/layui-vue/types/component/page/index.vue";
import Wingoodsx from "./module/WinGoodsX.vue";//弹窗-选择商品
import { OrderBuyerNEW, GoodsX, OrderBuyerID, OrderBuyerList, OrderBuyerUP, OrderBuyerFinish } from "../../../api/module/user"; //请求模块
import { useAppStore } from '../../../store/app'//刷新模块

import PNDB from "./indexPN";
const PN = new PNDB;
const PS = ref("new");//当前页面状态-new建单据|id看单据
// 按钮显示与禁用
const button_v = ref({
	"verify": { "show": true, "disabled": false },//验证按钮
	"new": { "show": true, "disabled": true },//新增按钮
	"save": { "show": true, "disabled": true },//保存按钮
	"finish": { "show": true, "disabled": true },//审核按钮

});
const RSD_hint = ref(false);//重复录入商品提示

const TAB_ID = ref("1");//选项卡ID默认值


// 点击-清除缓存
const reloadx = () => {
	// location.reload();
	refresh()
}
// 刷新模块
const appStore = useAppStore()
// 刷新模块
const refresh = () => {
	console.log("刷新模块");
	appStore.routerAlive = false
	setTimeout(function () {
		appStore.routerAlive = true
	}, 500)
}

const Form_Ref = ref<InstanceType<typeof MyModal> | null>(null);//当前窗口表单Ref
const Form_Model = ref({
	table_header: {
		"dbid": "",//系统单号
		"sup_dbid": "供应厂商",//供应厂商
		"time_new": { "avl": "", "mp": "", "txt": "创建时间" },//创建时间
		"time_up": { "avl": "", "mp": "", "txt": "修改时间" },//修改时间
		"original_no": "原始单号",//原始单号
		"remark": "单据备注",//单据备注
		"type": "A1",//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
		"state": "A",//单据状态_A草稿B审核C作废
	},//表头
	table_detail: [
		{
			"id": 1,//结构ID-系统编码仅限前端数组包装使用与后端无关
			"goods_dbid": "",//系统编码-商品数据编号
			"in_code": "",//录入码
			"barcode": "",//条码
			"goods_name": "",//名称
			"unit": "",//单位
			"number": 0,//数量
			"prc_in": 0.00,//档案进价
			"prc_in_actual": 0.00,//实际进价
			"unit_pack": { "val": "", "mp": "", "txt": "是否大单位" },//是否大单位
			"remark": ""//行备注
		}
	],//表格内容
});//当前窗口表单Model

// 历史单据-初始化数据
const Table_list = ref({
	header: {
		"dbid": "",//系统单号
		"sup_dbid": "供应厂商",//供应厂商
		"original_no": "原始单号",//原始单号
		"remark": "单据备注",//单据备注
		"type": "A1",//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
		"state": "A",//单据状态_A草稿B审核C作废

	},//历史单据-当前激活单据
	list: [
		{
			"dbid": "",//系统单号
			"sup_dbid": "",//供应厂商
			"time_new": { "avl": "", "mp": "", "txt": "创建时间" },//创建时间
			"time_up": { "avl": "", "mp": "", "txt": "修改时间" },//修改时间
			"original_no": "",//原始单号
			"remark": "",//单据备注
			"detail_length_insert": 0,//明细长度
			"type": { "avl": "", "mp": "", "txt": "单据类型" },//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
			"state": { "avl": "", "mp": "", "txt": "单据状态" },//单据状态_A草稿B审核C作废
		}
	],//历史单据-单据列表
	detail: [
		{
			"id": 1,//结构ID-系统编码仅限前端数组包装使用与后端无关
			"goods_dbid": "",//系统编码-商品数据编号
			"in_code": "",//录入码
			"barcode": "",//条码
			"goods_name": "",//名称
			"unit": "",//单位
			"number": 0,//数量
			"prc_in": 0.00,//档案进价
			"prc_in_actual": 0.00,//实际进价
			"unit_pack": { "val": "", "mp": "", "txt": "是否大单位" },//是否大单位
			"remark": ""//行备注
		}
	],//历史单据-当前点激活的单据-单据明细
});

// 按钮点击-保存订单
const click_FORM = function (res: any) {
	console.log("按钮点击", res.target.innerText);
	if (res.target.innerText == "验证") {

		Form_Ref.value.validate((isValidate: any, model: any, errors: any) => {
			if (isValidate) {
				if (model.table_detail.length < 1) {
					layer.msg("请增加单据明细", { icon: 2 });
				} else {
					let is_ok = false;
					let is_val = "";
					Form_Model.value.table_detail.forEach((item, index) => {
						console.log("数组行", index, item);
						if (item.in_code == "" || item.number == null || item.number == 0) {
							is_ok = true;
							is_val = is_val + "/" + (index + 1);
						}
					});
					if (is_ok) {
						layer.confirm("错误行:" + is_val, {
							title: "数据验证不通过",
							btn: [
								{
									text: '确定', callback: () => {
										layer.closeAll();
									}
								},
							]
						});
					} else {
						// 验证通过
						button_v.value.save.disabled = false;//开放保存按钮
						button_v.value.finish.disabled = true;//审核按钮

					}
				}
			} else {
				layer.msg("数据验证不通过", { icon: 2 });
				button_v.value.verify.disabled = false;//验证按钮
				button_v.value.save.disabled = true;//保存按钮
				button_v.value.finish.disabled = true;//审核按钮
			};
		});

	} else if (res.target.innerText == "保存") {
		Form_Ref.value.validate((isValidate: any, model: any, errors: any) => {
			if (isValidate) {
				HTTP_FORM(model);//HTTP请求-保存订单

			}
		});


	} else if (res.target.innerText == "审核") {
		button_v.value.finish.disabled = true;//审核按钮
		button_v.value.save.disabled = true;//保存按钮
		Form_Ref.value.validate((isValidate: any, model: any, errors: any) => {
			if (isValidate) {
				HTTP_Finish(model);//HTTP请求-审核

			}
		});

	} else {
		console.log("溢出");
	}

	return;

};
// HTTP请求-保存订单
const HTTP_FORM = async (model: any) => {
	console.log("HTTP请求", model);

	if (PS.value == 'new') {
		let data = await OrderBuyerNEW(model);//新增
		console.log("HTTP请求-保存订单-回调", data);
		if (data.code == 200) {
			layer.msg(data.msg, { icon: 1 }, async () => {
				button_v.value.finish.disabled = false;//开放审核按钮
				button_v.value.save.disabled = true;//保存按钮
				HTTP_GO_ID(data.data.dbid, "id");//查询一条

			});
		} else {
			layer.msg(data.msg, { icon: 2 });
		}
	} else {
		let data = await OrderBuyerUP(model);//修改
		console.log("HTTP请求-保存订单-回调", data);
		if (data.code == 200) {
			layer.msg(data.msg, { icon: 1 }, async () => {
				button_v.value.finish.disabled = false;//开放审核按钮
				button_v.value.save.disabled = true;//保存按钮
				HTTP_GO_ID(data.data.dbid, "id");//查询一条

			});
		} else {
			layer.msg(data.msg, { icon: 2 });
		}
	}



};

// HTTP请求-审核
const HTTP_Finish = async (model: any) => {
	console.log("HTTP请求-审核", model);
	button_v.value.finish.disabled = false;//开放审核按钮
	let data = await OrderBuyerFinish(model);//审核
	console.log("HTTP请求-审核-回调", data);

	if (data.code == 200) {
		layer.msg(data.msg, { icon: 1 }, async () => {
			button_v.value.verify.disabled = true;//验证按钮
			button_v.value.finish.disabled = true;//审核按钮
			button_v.value.save.disabled = true;//保存按钮
			HTTP_GO_ID(data.data.dbid, "id");//查询一条

		});
	} else {
		layer.msg(data.msg, { icon: 2 });
	}



};

// 表格-单据编辑-行单击
const table_click = (row: any) => {
	console.log("表格-行单击", row);
	button_v.value.verify.disabled = false;//验证按钮
	button_v.value.save.disabled = true;//保存按钮
	button_v.value.finish.disabled = true;//审核按钮
};
// 表格-历史单据-行单击
const Table_list_click = (row: any) => {
	console.log("历史单据-行单击", row);
	Table_list.value.header = {
		"dbid": row.dbid,//系统单号
		"sup_dbid": row.sup_dbid,//供应厂商
		"original_no": row.original_no,//原始单号
		"remark": row.remark,//单据备注
		"type": row.type,//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
		"state": row.state,//单据状态_A草稿B审核C作废

	},
		HTTP_GO_ID(row.dbid, "Table_list");
};

//表格-新增行
const Add = () => {
	console.log("多单位-新增行");
	Form_Model.value.table_detail.push({
		"id": (Form_Model.value.table_detail.length + 1),//结构ID-仅限前端数组包装使用与后端无关
		"goods_dbid": "",//商品数据编号
		"in_code": "",//录入码
		"barcode": "",//条码
		"goods_name": "",//名称
		"unit": "",//单位
		"number": 0,//数量
		"prc_in": 0.00,//档案进价
		"prc_in_actual": 0.00,//实际进价
		"unit_pack": { "val": "", "mp": "", "txt": "是否大单位" },//是否大单位
		"remark": ""//行备注
	});
	button_v.value.verify.disabled = false;//验证按钮
	button_v.value.save.disabled = true;//保存按钮
	button_v.value.finish.disabled = true;//审核按钮
	console.log("当前表数据", Form_Model.value.table_detail.length, Form_Model.value);

};
// 按钮点击-新建订单
function OrderBuyer_new() {
	console.log("按钮点击-新建订单");
	PS.value = "new";
	Form_Model.value = {
		table_header: {
			"dbid": "",//系统单号
			"sup_dbid": "供应厂商",//供应厂商
			"time_new": { "avl": "", "mp": "", "txt": "创建时间" },//创建时间
			"time_up": { "avl": "", "mp": "", "txt": "修改时间" },//修改时间
			"original_no": "",//原始单号
			"remark": "",//单据备注
			"type": "A1",//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
			"state": "A",//单据状态_A草稿B审核C作废
		},//表头
		table_detail: [
			{
				"id": 1,//结构ID-系统编码仅限前端数组包装使用与后端无关
				"goods_dbid": "",//系统编码-商品数据编号
				"in_code": "",//录入码
				"barcode": "",//条码
				"goods_name": "",//名称
				"unit": "",//单位
				"number": 0,//数量
				"prc_in": 0.00,//档案进价
				"prc_in_actual": 0.00,//实际进价
				"unit_pack": { "val": "", "mp": "", "txt": "是否大单位" },//是否大单位
				"remark": ""//行备注
			}
		],//表格内容
	}
}



// 表格-删除行
const Del = (data: any) => {
	console.log("表格-删除行", data);
	console.log("当前表数据", Form_Model.value.table_detail.length, Form_Model.value);
	layer.confirm('确定删除此条数据？', { btn: [{ text: '确定', callback: () => { Form_Model.value.table_detail.forEach((item, index) => { if (item.id === data.id) { Form_Model.value.table_detail.splice(index, 1); }; }); layer.closeAll(); } }, { text: '取消', callback: () => { layer.closeAll(); } }] });
};
// 历史单据-编辑
const Edit = (event: any, data: any) => {
	console.log("历史单据-编辑", event, data);
	console.log("SSSSSSSSS", event.target.innerText);
	PS.value = "id";//当前页面状态-new建单据|id看单据|up改单据
	Form_Model.value.table_header.dbid = data.dbid;
	EnterKey_GO_ID(data.dbid);
	TAB_ID.value = "1";//选项卡ID默认值

};

// 录入码输入框-回车键监听
function handleEnterKey(key: string, data: any) {
	// console.log("弹起回车键", key, data);
	HTTP_GoodsID2(key, data);
};
// 系统单号输入框-回车键监听
function EnterKey_GO_ID(dbid: string) {
	// console.log("弹起回车键", key, data);
	Form_Model.value.table_detail = [];
	Add();
	HTTP_GO_ID(dbid, "id");
};
// HTTP请求-查询一条单据
async function HTTP_GO_ID(dbid: string, key: string) {
	// console.log("HTTP请求", model);
	let data = await OrderBuyerID({ dbid });
	// layer.load(0, { time: 500 });
	// console.log("HTTP请求-回调", data);
	if (data.code == 200) {

		PS.value = "id";
		// Table_list列表来源查询一条
		if (key == "Table_list") {
			Table_list.value.detail = [];
			if (data.data.table_detail.length > 0) {
				Table_list.value.detail = data.data.table_detail;//单据明细
			}
		} else {
			Form_Model.value.table_detail = [];
			Form_Model.value.table_header = {
				"dbid": data.data.dbid,//系统单号
				"sup_dbid": data.data.sup_dbid,//供应厂商
				"time_new": data.data.time_new,//创建时间
				"time_up": data.data.time_up,//修改时间
				"original_no": data.data.original_no,//原始单号
				"remark": data.data.remark,//单据备注
				"type": data.data.type,//单据类型_A1采购入库B1采购退货C1赠品入库D1报损出库
				"state": data.data.state,//单据状态_A草稿B审核C作废
			}//表头
			// if (data.data.table_detail.length > 0) {
			Form_Model.value.table_detail = data.data.table_detail;//单据明细
			// }
			layer.msg("正在查阅单据", { time: 500 })

		}

	} else {
		layer.msg(data.msg, { icon: 2 });
	}

}
// HTTP请求-扫码模糊查询商品
async function HTTP_GoodsID2(key: string, model: any) {
	// console.log("HTTP请求", model);
	let data = await GoodsX({ key, model });
	layer.load(0, { time: 500 });
	console.log("HTTP请求-回调", data);
	if (data.code == 200) {
		if (data.count > 0) {
			goodsx_add(model.id, data.db);//(录入表格数据行的id,远程返回的数据)

		}
	} else {
		layer.msg(data.msg, { icon: 2 });
	}

}
const layout1a = ref<LayoutKey[]>(['count', 'prev', 'page', 'next', 'limits', 'refresh', 'skip']);//分页条块

const page = ref({
	total: 0,//总行数
	limit: 5,//每页行数
	current: 1,//当前页
	SearchField: "dbid",//默认搜索字段
	SearchOperator: "LIKE",//默认搜索查询表达式
	SearchaAtistop: "",//默认搜索关键词
	SearchaSort: "DESC",//默认搜索排序方式ASE,DESC升降序
	SearchaSortField: "id",//默认排序字段
	additional: {
		use: 0,//启用额外查询方法-0否-1是。
		SearchField: "dbid",//默认搜索字段
		SearchOperator: "LIKE",//默认搜索查询表达式
		SearchaAtistop: "",//默认搜索关键词
	}
});
// 分页点击
const change = function ({ current, limit }: any) {
	console.log("当前页码:" + current + " 每页数量:" + limit);
	page.value.current = current;//当前页码
	page.value.limit = limit;//每页数量
	click_OrderBuyerList();
};

// HTTP请求-查询单据列表
const click_OrderBuyerList = async () => {
	// console.log("查询单据列表", page.value);
	let data = await OrderBuyerList(page.value);
	layer.load(0, { time: 500 });
	// console.log("HTTP请求-回调", data.data.data);
	if (data.code == 200) {
		Table_list.value.detail = [];
		// if (data.data.data.length > 0) {
		// goodsx_add(model.id, data.db);//(录入表格数据行的id,远程返回的数据)
		page.value.total = data.data.total;//数据总行数
		Table_list.value.list = data.data.data;
		// }



	} else {
		layer.msg(data.msg, { icon: 2 });
	}

}









const goodsxRef = ref<InstanceType<typeof MyModal> | null>(null);// 子窗口Ref
// 打开弹窗-选择商品
const goodsx_add = function (table_db_item_id: number, data: any) {
	console.log("打开弹窗", table_db_item_id, data);
	goodsxRef.value?.goodsx_fnx(table_db_item_id, data);//子组件方法
};
//监听子组件
const goodsx_fn = function (table_db_item_id: number, db: any) {
	console.log("我的父组件中的方法?", table_db_item_id, db);
	console.log("入坑行", table_db_item_id);
	console.log("选中商品ID", db.dbid);
	let RSD = false;//商品是否重复


	Form_Model.value.table_detail.forEach((item, index) => {
		// console.log("坑中原有数据", item.goods_dbid);
		if (item.goods_dbid == db.dbid) {
			console.log(item.goods_dbid + "=" + item.goods_dbid);
			RSD = true;//商品是否重复

		}
	});

	// 商品重复提示录入
	if (RSD && RSD_hint.value) {
		layer.confirm("商品已在单据中,是否重复录入？", {
			title: "是否重复录入？",
			btn: [{
				text: '录入', callback: (id: string) => {
					console.log("写入商品", id);
					layer.closeAll();
					// 写入商品
					Form_Model.value.table_detail.forEach((item, index) => {
						if (item.id == table_db_item_id) {
							Form_Model.value.table_detail[index].goods_dbid = db.dbid;//商品数据编号
							Form_Model.value.table_detail[index].barcode = db.barcode;//条码
							Form_Model.value.table_detail[index].goods_name = db.name;//名称
							Form_Model.value.table_detail[index].unit = db.unit;//单位
							Form_Model.value.table_detail[index].prc_in = db.prc_in;//档案进价
							Form_Model.value.table_detail[index].unit_pack = db.unit_pack.mp;//是否大单位
						}
					})
				}
			},
			{
				text: '取消', callback: (id: string) => {
					console.log("不写商品", id);
					layer.closeAll();
				}
			},
			]
		});
	} else {
		// 写入商品
		Form_Model.value.table_detail.forEach((item, index) => {
			if (item.id == table_db_item_id) {
				Form_Model.value.table_detail[index].goods_dbid = db.dbid;//商品数据编号
				Form_Model.value.table_detail[index].barcode = db.barcode;//条码
				Form_Model.value.table_detail[index].goods_name = db.name;//名称
				Form_Model.value.table_detail[index].unit = db.unit;//单位
				Form_Model.value.table_detail[index].prc_in = db.prc_in;//档案进价
				Form_Model.value.table_detail[index].unit_pack = db.unit_pack.mp;//是否大单位
			}
		})
	}






};



// 生命周期
onMounted(() => {
	// ListSubmit();
	// console.log(bbs);
});
</script>
<style>
.layui-form-item {
	margin: 0px !important;
	padding: 0px !important;
	/* background-color: rgb(255, 0, 0); */
}
</style>